package com.fzb.zrlog.simple.dao.impl;

import com.fzb.common.dao.impl.DAO;
import com.fzb.zrlog.simple.dao.api.ICommentDAO;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Comment extends DAO implements ICommentDAO {
    public Comment() {
        tableName = "comment";
        pk = "commentId";
    }

    @Override
    public Map<String, Object> getCommentsByPage(int page, int pageSize) {
        return null;
    }

    @Override
    public long getCommentCount() {
        try {
            return (int) queryFirst("select count(1) cnt from comment", new Object[]{}).get("cnt");
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public long getToDayCommentCount() {
        return 0;
    }

    @Override
    public Map<String, Object> noRead(int page, int pageSize) {
        Map<String, Object> root = new HashMap<>();
        try {
            List<Map<String, Object>> comments = queryPagination(page, pageSize, ALL);
            root.put("rows", comments);
            return root;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return root;
    }

    @Override
    public List<Map<String, Object>> getCommentsByLogId(int logId) {
        try {
            return set("logId", logId).queryList(ALL);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return new ArrayList<>();
    }
}
